package engine.light;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;

import static org.lwjgl.opengl.GL11.*;

public abstract class Light {

	private FloatBuffer diffuse;
	private FloatBuffer specular;
	private float shininess;
	
	private boolean enable = true;
	
	public Light() {
		diffuse = BufferUtils.createFloatBuffer(4);
		diffuse.put(3, 1);
		specular = BufferUtils.createFloatBuffer(4);
		specular.put(3, 1);
	}
	
	public FloatBuffer getDiffuse() {
		return diffuse;
	}
	
	public void setDiffuse(float r, float g, float b) {
		diffuse.put(0, r);
		diffuse.put(1, g);
		diffuse.put(2, b);
	}

	public FloatBuffer getSpecular() {
		return specular;
	}

	public void setSpecular(float r, float g, float b) {
		specular.put(0, r);
		specular.put(1, g);
		specular.put(2, b);
	}

	public float getShininess() {
		return shininess;
	}

	public void setShininess(float shininess) {
		this.shininess = shininess;
	}
	
	public void apply(int lightSource) {
		diffuse.rewind();
		specular.rewind();
		
		glEnable(lightSource);
		glLight(lightSource, GL_DIFFUSE, diffuse);
		glLight(lightSource, GL_SPECULAR, specular);
		glLightf(lightSource, GL_SHININESS, shininess);
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}
}
